1
00:00:00,120 --> 00:00:02,170
Now moving on to looping.

2
00:00:02,340 --> 00:00:11,880
So we introduce looping in our bash scripting video and we took the for loops and we made one line for

3
00:00:11,880 --> 00:00:13,470
loops and those should be familiar to you.

4
00:00:13,500 --> 00:00:17,430
So for loop is just a start to finish of an inter it right.

5
00:00:17,430 --> 00:00:24,630
We wanted to run that pinging scanner for example and we started at the one and we ended at 256 on our

6
00:00:24,630 --> 00:00:26,180
IP suite.

7
00:00:26,190 --> 00:00:29,640
Now we're going to introduce that in Python form.

8
00:00:29,790 --> 00:00:32,210
And we're also going to introduce a while loop.

9
00:00:32,220 --> 00:00:37,470
Now the while loop is going to come back into play later on in this course especially when we get into

10
00:00:37,470 --> 00:00:39,630
the exploit development part of the course.

11
00:00:39,630 --> 00:00:44,910
So a while loop just think of it that it executes as long as something is true.

12
00:00:45,000 --> 00:00:49,740
So let's make a new section here we're going to do a new line as usual and we're just going to go ahead

13
00:00:49,740 --> 00:00:56,370
to say something like looping and let's go ahead and start with for loops.

14
00:00:56,370 --> 00:01:07,080
So we'll do four loops and note that this is just the start to finish of and iterate.

15
00:01:07,640 --> 00:01:14,670
OK so let's say for example that we have a list.

16
00:01:14,760 --> 00:01:15,130
OK.

17
00:01:15,180 --> 00:01:20,130
Let's go back to lists and we'll say vegetables and let's just throw some vegetables in there.

18
00:01:20,130 --> 00:01:21,150
You can pick whatever you want.

19
00:01:21,150 --> 00:01:22,740
I'm going to do a cucumber.

20
00:01:23,700 --> 00:01:29,700
I'm going to do spinach and how about cabbage cake.

21
00:01:29,730 --> 00:01:35,640
And again your list can look however you want to look now for this for loop.

22
00:01:35,640 --> 00:01:38,330
We're going to say for X..

23
00:01:38,400 --> 00:01:40,530
And remember same thing with bash.

24
00:01:40,830 --> 00:01:42,360
X can be whatever you want to call it.

25
00:01:42,360 --> 00:01:45,390
You can call this for veggies call whatever you want.

26
00:01:45,750 --> 00:01:48,670
I just like to use a letter because it's simple to type out.

27
00:01:48,700 --> 00:01:57,420
We're going to say for x in vegetables we're just going to print x and what do we think this is going

28
00:01:57,420 --> 00:01:58,340
to do.

29
00:01:58,680 --> 00:02:02,050
This is going to go through this list right.

30
00:02:02,070 --> 00:02:04,800
It says Save for every item in vegetables.

31
00:02:04,800 --> 00:02:06,270
I want you to print that out.

32
00:02:06,420 --> 00:02:11,640
So we're gonna grab cucumber we're gonna grab spinach we're gonna grab cabbage print print print.

33
00:02:11,760 --> 00:02:12,750
So let's take a look at that.

34
00:02:12,750 --> 00:02:13,770
Let's go ahead and save it.

35
00:02:15,010 --> 00:02:17,220
We're on our script here.

36
00:02:17,450 --> 00:02:20,580
You can see that it printed cucumbers spinach and cabbage.

37
00:02:20,600 --> 00:02:22,790
So again you've seen this before.

38
00:02:22,790 --> 00:02:24,750
Just a classic example of for.

39
00:02:24,920 --> 00:02:28,940
As long as we have something to iterate through we're iterating through a list here.

40
00:02:28,940 --> 00:02:34,160
And remember before again we were like sequins one through two fifty five.

41
00:02:34,160 --> 00:02:37,000
We iterated through that to do our pink sweep.

42
00:02:37,040 --> 00:02:41,690
So we're just iterating through something that's it really basic.

43
00:02:41,690 --> 00:02:51,530
Now we also have wall loops so we'll say while loops and these execute as long as true.

44
00:02:52,520 --> 00:03:00,260
So later on you're going to see something that says while True the capital while true we're going to

45
00:03:00,260 --> 00:03:01,460
do something.

46
00:03:01,460 --> 00:03:03,310
Don't worry about that right now.

47
00:03:03,530 --> 00:03:14,180
For this example we're gonna do is we're going to say i equals 1 k and so he said there will I.

48
00:03:14,210 --> 00:03:15,280
That's equal to 1.

49
00:03:15,290 --> 00:03:24,350
Now let's do a while loop we're going to say Well I as less than 10 I want you to go ahead and print

50
00:03:24,380 --> 00:03:25,280
out I.

51
00:03:27,170 --> 00:03:32,180
And then we're going to iterate I plus equals 1.

52
00:03:32,210 --> 00:03:35,870
So this should all start tying together from what you saw earlier.

53
00:03:35,870 --> 00:03:40,160
Remember that we had the plus equals and we're adding one to something.

54
00:03:40,160 --> 00:03:43,210
So what we're doing here is you're saying hey I equals 1.

55
00:03:43,460 --> 00:03:47,850
And you know it while i is less than 10 I want you to go ahead and print out.

56
00:03:47,850 --> 00:03:51,670
I then we're going to say hey I is plus equals 1.

57
00:03:51,680 --> 00:03:55,950
So that means I'm now going to be two then we're gonna go back through this loop again.

58
00:03:55,970 --> 00:03:58,630
Now while 2 is less than 10.

59
00:03:58,790 --> 00:04:04,670
Go ahead and print out that it's to make it three 3s less than 10 over and over and over and over until

60
00:04:04,700 --> 00:04:07,860
this condition is no longer true.

61
00:04:07,970 --> 00:04:13,670
The second that this eye becomes 10 this loop is not no longer true and it's going to stop.

62
00:04:14,300 --> 00:04:18,460
So we're gonna go ahead and save this here.

63
00:04:18,520 --> 00:04:29,460
Let's go ahead and print this out and you can see that we just printed 1 3 9 as expected so you're gonna

64
00:04:29,470 --> 00:04:32,170
get to see these again you're going to get examples of them again.

65
00:04:32,200 --> 00:04:39,820
As of right now I just want you to understand that a for loop isn't inner it and a wall loop executes

66
00:04:39,820 --> 00:04:40,810
as long as true.

67
00:04:41,410 --> 00:04:47,830
OK so don't worry about how they're used quite yet just understand what they are what they mean and

68
00:04:47,830 --> 00:04:52,510
then you're going to see them come up and practical examples later on it'll make a lot more sense as

69
00:04:52,510 --> 00:04:53,480
we go through it.

70
00:04:53,590 --> 00:04:55,670
So we're going to move on to the next video.

71
00:04:55,900 --> 00:04:57,610
I'm going to go ahead and catch you over there.
